#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：批量构建trojan连接.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2025/2/11 下午3:56 
"""

# trojan_url = f'trojan://bpb-trojan@www.vpslook.com:443?security=tls&sni={target_host}&alpn=h3&fp=randomized&allowlnsecure=1&type=ws&host={target_host}&path=%2Ftr%3Fed%3D2560#BPB'

import urllib.parse


def extract_domain(url):
	"""
	从URL中提取域名
	"""
	# 解析URL
	parsed_url = urllib.parse.urlparse(url)
	# 域名即为netloc部分
	domain = parsed_url.netloc
	return domain


def main():
	# 目标字符串模板
	trojan_template = "trojan://bpb-trojan@www.vpslook.com:443?security=tls&sni={target_host}&alpn=h3&fp=randomized&allowinsecure=1&type=ws&host={target_host}&path=%2Ftr%3Fed%3D2560#BPB"

	# 文件路径
	url_file = "OK.txt"

	# 读取文件内容
	with open(url_file, "r") as f:
		urls = [line.strip() for line in f if line.strip()]

	# 遍历每个URL，提取域名并生成目标字符串
	result = []
	for url in urls:
		domain = extract_domain(url)
		if domain:
			# 替换模板中的 target_host
			trojan_url = trojan_template.format(target_host=domain)
			result.append(trojan_url)

	# 输出结果到控制台
	for url in result:
		print(url)


if __name__ == "__main__":
	main()